package org.itboys.commons.utils.encode;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
/**
 * 二维码工具类
 * @author ok
 *
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public class TwoCodeUtils {
	public static String createBarCode(String content,String path){

		return null;
	}


	/**
	 * 生成二维码
	 * @param content  url
	 * @return
	 */
	public static String createTwoDimensionalCode(String content,String name, String savePath) {
		try {
			StringBuffer sb = new StringBuffer("");

			MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
			Map hints = new HashMap();
			hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
			BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 400, 400, hints);
			sb.append("/").append(name).append(".jpg");
			File file1 = new File(savePath,  name+".jpg");
			MatrixToImageWriter.writeToFile(bitMatrix, "jpg", file1);
			return sb.toString();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}


}
